﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.WebPages;
using System.IO;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;

namespace Infrastructure.WebMvc.Helpers
{
    public static class SecurityHelper 
    {
        public static HelperResult LoginStatus(this HtmlHelper helper)
        {            
            return new HelperResult(
                    delegate(TextWriter tw) {
                        try
                        {                            
                            if (HttpContext.Current.User.Identity.IsAuthenticated)
                            {
                                tw.Write( helper.Label("logout").ToHtmlString());
                                
                            }

                            else
                                tw.Write(helper.Label("login").ToHtmlString()); 
                        }
                        catch (Exception ex)
                        {
                            tw.Write(helper.Label("login").ToHtmlString());                                
                        }                        
                    }
                );
        }
    }
}
